<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>上传图片</title>
</head>
<body>
<fieldset style="margin:10px;padding:15px;" class="layui-elem-field layui-field-title">
		<legend>图片上传</legend>
		<button class="layui-btn" id="test1">
			<i class="layui-icon">&#xe67c;</i>上传图片
		</button>
		<table class="layui-table layui-anim layui-anim-upbit">
			<colgroup>
				<col width="5%">
				<col width="10%">
				<col width="10%">
			</colgroup>
			<thead>
				<tr>
					<th>文件名</th>
					<th>图片</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="demolist2"></tbody>
		</table>
	</fieldset>
	<script type="text/javascript">
	var code=<%=request.getParameter("code")%>
	renderUpload("test1","/EmployeeUploadServlet",{code:code},function(res){
		console.log(res)
		if(res.code==1){
			layer.msg("上传成功")
			showPic(res.image)
		}
	})
	init();
	function init(){
		ajax('/employee',{action:'get',code:code},'json',function(data){
			
			var image=data.image;
			console.log(data.image)
			if(image) showPic(image);
			else $("#demolist2").html('');
		})
	}
	function showPic(image){
		var html="<tr><td>"+image
		+"</td><td><img src='/image/"+image+"' class='layui-upload-img'></td>"
		+"<td><input type='button' onclick='delPic(code)' class='layui-btn' value='删除'></td></tr>";
		$("#demolist2").html(html)
	}
	function delPic(code){
		ajax('/employee',{action:'delPic',code:code},'text',function(data){
			if(data==1){
				layer.msg("删除成功",{time:1000},init)
			}else{
				layer.msg("删除失败")
			}
		})
	}
	</script>
</body>
</html>